unit DoljnostFood;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dRoot, DB, StdCtrls, Buttons, ExtCtrls, ComCtrls, cxStyles,
  dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinCaramel, dxSkinCoffee,
  dxSkinDarkSide, dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinPumpkin,
  dxSkinSilver, dxSkinStardust, dxSkinSummer2008, dxSkinsDefaultPainters,
  dxSkinValentine, dxSkinXmas2008Blue, dxSkinscxPCPainter, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  IBCustomDataSet, cxGridLevel, cxClasses, cxControls, cxGridCustomView,
  cxGrid, IBQuery, dxSkinsdxBarPainter, cxButtonEdit, cxLabel, cxCalendar,
  cxRadioGroup, dxBar, cxBarEditItem;

type
  TfmDoljnostFood = class(TdlgRoot)
    dsDoljnost: TDataSource;
    qdoljnost: TIBQuery;
    dbgDoljnost: TcxGrid;
    tvDoljnost: TcxGridDBTableView;
    cxGridLevel2: TcxGridLevel;
    qdoljnostDPID: TIntegerField;
    qdoljnostDOLID: TIntegerField;
    qdoljnostPID: TIntegerField;
    qdoljnostPLASTNAME: TIBStringField;
    qdoljnostPNAME: TIBStringField;
    qdoljnostPPATRONYMIC: TIBStringField;
    qdoljnostDOLJN: TIBStringField;
    qdoljnostPARENTS_LIST: TIBStringField;
    tvDoljnostPID: TcxGridDBColumn;
    tvDoljnostPLASTNAME: TcxGridDBColumn;
    tvDoljnostPNAME: TcxGridDBColumn;
    tvDoljnostPPATRONYMIC: TcxGridDBColumn;
    tvDoljnostDOLJN: TcxGridDBColumn;
    tvDoljnostPARENTS_LIST: TcxGridDBColumn;
    dxBarManager1: TdxBarManager;
    dxBarManager1Bar4: TdxBar;
    bTrEdit: TdxBarButton;
    dxBarDockControl1: TdxBarDockControl;
    qdoljnostM: TIntegerField;
    tvDoljnostM: TcxGridDBColumn;
    beSelectDoljnost: TcxBarEditItem;
    bbsearching: TdxBarButton;
    qtemp: TIBQuery;
    IntegerField1: TIntegerField;
    IntegerField2: TIntegerField;
    IntegerField3: TIntegerField;
    IBStringField1: TIBStringField;
    IBStringField2: TIBStringField;
    IBStringField3: TIBStringField;
    IBStringField4: TIBStringField;
    IBStringField5: TIBStringField;
    IntegerField4: TIntegerField;
    qSD: TIBQuery;
    qSDSDNAME: TIBStringField;
    qSDSDID: TIntegerField;
    qSDSDPARID: TIntegerField;
    qSDSDISDELETE: TIntegerField;
    procedure bTrEditClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure tvDoljnostCellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure tvDoljnostCustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure cxBarEditItem3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure beSelectDoljnostChange(Sender: TObject);
    procedure bbsearchingClick(Sender: TObject);
  private
    { Private declarations }
    fDoljn, ufDoljn: string;
  public
    { Public declarations }
  end;

var
  fmDoljnostFood: TfmDoljnostFood;

implementation
uses DBinv, InvTypes, InvProc, AddEditDoljnostFood, Filter;
{$R *.dfm}

procedure TfmDoljnostFood.bTrEditClick(Sender: TObject);
var tmp_id: Integer;
begin
  inherited;
  if qdoljnost.IsEmpty then
    Exit;
  if qdoljnostPID.IsNull then Exit;
  tmp_id := qdoljnostDPID.AsInteger;
  try
    if fmAddEditDoljnostFood = nil then
      fmAddEditDoljnostFood := TfmAddEditDoljnostFood.Create(self);
    fmAddEditDoljnostFood.dpid := qdoljnostDPID.AsInteger;
    if fmAddEditDoljnostFood.showModal = mrOk then begin
      qdoljnost.Close;
      qdoljnost.Open;
      qdoljnost.DisableControls;
      qdoljnost.Locate('dpid', tmp_id, []);
      qdoljnost.EnableControls;
    end;
  finally
    fmAddEditDoljnostFood.Release;
    fmAddEditDoljnostFood := nil;
  end;
end;

procedure TfmDoljnostFood.FormShow(Sender: TObject);
begin
  inherited;
  qdoljnost.Close;
  qdoljnost.Open;
end;

procedure TfmDoljnostFood.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  qdoljnost.Close;
end;

procedure TfmDoljnostFood.tvDoljnostCellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  inherited;
  bTrEditClick(Self);
end;

procedure TfmDoljnostFood.tvDoljnostCustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  inherited;
  ACanvas.Canvas.Font.Color := clBlack;
  if AViewInfo.GridRecord.Values[tvDoljnostM.Index] = 0 then begin
    ACanvas.Canvas.Brush.Color := $008080FF;
  end
  else
    ACanvas.Canvas.Brush.Color := clMoneyGreen;
  ADone := False;
end;

procedure TfmDoljnostFood.cxBarEditItem3PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  inherited;
  try
    if fmFilter = nil then
      fmFilter := TfmFilter.Create(self);
    fmFilter.qFilter.ParamByName('TFNUM').AsInteger := 98;
    fmFilter.qSD.SelectSQL.Clear;
    fmFilter.qSD.SelectSQL.Text := qSD.SQL.Text;
    fmFilter.n_sys_dic := 28;
    fmFilter.bExtend.Visible := False;
    fmFilter.is_save := False;
    if fmFilter.ShowModal = mrOk then begin
      fDoljn := '';
      ufDoljn := '';
      fDoljn := fmFilter.filter;
      ufDoljn := fmFilter.ufilter;
      beSelectDoljnost.EditValue := ufDoljn;
    end;
  finally
    fmFilter.Release;
    fmFilter := nil;
  end;
end;

procedure TfmDoljnostFood.beSelectDoljnostChange(Sender: TObject);
begin
  inherited;
  
  bbsearching.Enabled := True;
  qdoljnost.Close;
end;

procedure TfmDoljnostFood.bbsearchingClick(Sender: TObject);
begin
  inherited;
  qdoljnost.SQL.Clear;
  qdoljnost.SQL.Text := qtemp.SQL.Text;
  if beSelectDoljnost.EditValue <> '' then
    qdoljnost.SQL.Add(' and ( ' + fDoljn + ' )');
  qdoljnost.SQL.Add(' order by 4');
  qdoljnost.Open;
  bbsearching.Enabled := False;
end;

end.

